<?php 

ob_start();
	
require '../include/library.inc.php';
require '../include/admin_login.inc.php';



$sql .= "SELECT
           order_id,
		   firstname,
		   lastname,
		   email,
		   country,
		   byear,
		   continent,
		   institution,
		   order_date,
		   status,
		   price,
		   paypal,
		   iass,
		   culinary,
		   dinner,
		   allergic,
		   note
          FROM
			orders
		WHERE del = '0'
		ORDER BY  order_id
		  ";

$result = query($sql);

//first of all unset these variables
unset($_SESSION['report_header']);
unset($_SESSION['report_values']);

//$_SESSION['report_header']=array("No.", "Име","Година", "E-mail", "Държава", "Регион", "Институция", "Дата", "Статус", "Цена", "Членска такса за IASS/AIS", "Кулинарно шоу", "Гала вечеря ", "хранителни алергии", "Забележка", "PayPal");
	
$i=0;
$table = '';

while ($row = mysql_fetch_object($result)) {
	
	
	$region = 'Европа';
	if($row->continent == 2)$region = 'Извън Европа';
	if($row->continent == 3) $region = 'Африка';
	$iass = 'не';
	$culinary = 'не';
	$gala = 'не';
	$allergy = 'не';
	
	if($row->iass) $iass = 'да';
	if($row->culinary) $culinary = 'да';
	if($row->dinner) $gala = 'да';
	if($row->allergic) $allergy = 'да';
	
	$status = '<b style=" color:#900">неплатена</b>';
	if($row->status == 4) $status = '<b style=" color:#900">Грешка при плащане</b>';
	if($row->status == 2) $status = '<b style="color:#093">Платена</b>';
	if($row->status == 3) $status = '<b style="color:#C60">Отказана</b>';
	
	$table .='<tr>';
	$table .='<td>'.$row->order_id.'</td>';
	$table .='<td>'.escape($row->firstname.' '.$row->lastname).'</td>';
	$table .='<td>'.$row->byear.'</td>';
	$table .='<td>'.$row->email.'</td>';
	$table .='<td>'.$row->country.'</td>';
	$table .='<td>'.$region.'</td>';
	$table .='<td>'.$row->institution.'</td>';
	$table .='<td>'.$row->order_date.'</td>';
	$table .='<td>'.$status.'</td>';
	$table .='<td>'.$row->price.'</td>';
	$table .='<td>'.$iass.'</td>';
	$table .='<td>'.$culinary.'</td>';
	$table .='<td>'.$gala.'</td>';
	$table .='<td>'.$allergy.'</td>';
	$table .='<td>'.stripslashes($row->note).'</td>';
	$table .='<td>'.urldecode($row->paypal).'</td>';
	
	/*$_SESSION['report_values'][$i][0] = $row->order_id;
	$_SESSION['report_values'][$i][1] = escape($row->firstname.' '.$row->lastname);
	$_SESSION['report_values'][$i][2] = $row->byear;
	$_SESSION['report_values'][$i][3] = $row->email;
	$_SESSION['report_values'][$i][4] = $row->country;
	$_SESSION['report_values'][$i][5] = $region;
	$_SESSION['report_values'][$i][6] = $row->institution;
	$_SESSION['report_values'][$i][7] = $row->order_date;
	$_SESSION['report_values'][$i][8] = $status;
	$_SESSION['report_values'][$i][9] = $row->price;
	$_SESSION['report_values'][$i][10] = $iass;
	$_SESSION['report_values'][$i][11] = $culinary;
	$_SESSION['report_values'][$i][12] = $gala;
	$_SESSION['report_values'][$i][13] = $allergy;
	$_SESSION['report_values'][$i][14] = stripslashes($row->note);
	$_SESSION['report_values'][$i][15] = $row->paypal;
	*/
	$table .='</tr>';
	$i++;
}

$table = '<table border="1">
			
				<tr bgcolor="#BFFFBF">
					<td>Регистрация No.</td>
					<td>Име и фамилия</td>
					<td>Година на раждане</td>
					<td>E-mail</td>
					<td>Държава</td>
					<td>Регион</td>
					<td>Институция</td>
					<td>От дата</td>
					<td>Статус</td>
					<td>Цена</td>
					<td>Членска такса за IASS/AIS</td>
					<td>Кулинарно шоу</td>
					<td>Гала вечеря </td>
					<td>Алергии</td>
					<td>Забележка</td>
					<td>Инфо от PayPal</td>
				</tr>
			


'.$table.'</table>';
	//code to download the data of report in the excel format
	$fn="registrations_".date("ymd-Gi").".xls";
	
	
	header("Content-type: application/vnd.ms-excel"); 
		//header("Content-type: text/csv"); 
		header("Content-Disposition: attachment; filename=$fn"); 
		header("Pragma: no-cache"); 
		header("Expires: 0"); 
		print "\xEF\xBB\xBF"; 
		print "$table"; 
	
	/*include_once("../include/export_excel.inc.php");
	//create the instance of the exportexcel format
	$excel_obj=new ExportExcel("$fn");
	//setting the values of the headers and data of the excel file 
	//and these values comes from the other file which file shows the data
	$excel_obj->setHeadersAndValues($_SESSION['report_header'],$_SESSION['report_values']); 
	//now generate the excel file with the data and headers set
	$excel_obj->GenerateExcelFile();
	//print_r($_SESSION['report_values']);*/
	
	
?>
